package com.gaohe.post.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.log.annotation.Log;
import com.gaohe.common.log.enums.BusinessType;
import com.gaohe.common.security.annotation.RequiresPermissions;
import com.gaohe.post.domain.FmPost;
import com.gaohe.post.service.IFmPostService;
import com.gaohe.common.core.web.controller.BaseController;
import com.gaohe.common.core.web.domain.AjaxResult;
import com.gaohe.common.core.utils.poi.ExcelUtil;
import com.gaohe.common.core.web.page.TableDataInfo;

/**
 * 圈子帖子Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/post")
public class FmPostController extends BaseController
{
    @Autowired
    private IFmPostService fmPostService;

    /**
     * 查询圈子帖子列表
     */
    @RequiresPermissions("post:post:list")
    @GetMapping("/list")
    public TableDataInfo list(FmPost fmPost)
    {
        startPage();
        List<FmPost> list = fmPostService.selectFmPostList(fmPost);
        return getDataTable(list);
    }

    /**
     * 导出圈子帖子列表
     */
    @RequiresPermissions("post:post:export")
    @Log(title = "圈子帖子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmPost fmPost)
    {
        List<FmPost> list = fmPostService.selectFmPostList(fmPost);
        ExcelUtil<FmPost> util = new ExcelUtil<FmPost>(FmPost.class);
        util.exportExcel(response, list, "圈子帖子数据");
    }

    /**
     * 获取圈子帖子详细信息
     */
    @RequiresPermissions("post:post:query")
    @GetMapping(value = "/{postId}")
    public AjaxResult getInfo(@PathVariable("postId") Long postId)
    {
        return success(fmPostService.selectFmPostByPostId(postId));
    }

    /**
     * 新增圈子帖子
     */
    @RequiresPermissions("post:post:add")
    @Log(title = "圈子帖子", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmPost fmPost)
    {
        return toAjax(fmPostService.insertFmPost(fmPost));
    }

    /**
     * 修改圈子帖子
     */
    @RequiresPermissions("post:post:edit")
    @Log(title = "圈子帖子", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmPost fmPost)
    {
        return toAjax(fmPostService.updateFmPost(fmPost));
    }

    /**
     * 删除圈子帖子
     */
    @RequiresPermissions("post:post:remove")
    @Log(title = "圈子帖子", businessType = BusinessType.DELETE)
	@DeleteMapping("/{postIds}")
    public AjaxResult remove(@PathVariable Long[] postIds)
    {
        return toAjax(fmPostService.deleteFmPostByPostIds(postIds));
    }
}
